package com.esri.core.geodatabase;

import com.esri.core.ags.LayerServiceInfo;
import com.esri.core.geodatabase.GeodatabaseEditError;
import com.esri.core.geodatabase.GeodatabaseFeatureTable;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.MapGeometry;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.n;
import com.esri.core.internal.tasks.ags.b;
import com.esri.core.internal.tasks.ags.c;
import com.esri.core.internal.tasks.ags.c.i;
import com.esri.core.internal.tasks.ags.f;
import com.esri.core.internal.tasks.ags.g;
import com.esri.core.internal.tasks.ags.p;
import com.esri.core.internal.tasks.ags.q;
import com.esri.core.internal.tasks.ags.w;
import com.esri.core.internal.tasks.ags.x;
import com.esri.core.internal.tasks.e;
import com.esri.core.internal.util.LocalGDBUtil;
import com.esri.core.internal.util.d;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.AttachmentInfo;
import com.esri.core.map.CallbackListener;
import com.esri.core.map.Feature;
import com.esri.core.map.FeatureEditResult;
import com.esri.core.map.FeatureResult;
import com.esri.core.tasks.SpatialRelationship;
import com.esri.core.tasks.query.QueryParameters;
import com.esri.core.tasks.query.RelatedQueryParameters;
import com.github.mikephil.charting.utils.Utils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.ObjectMapper;

/* loaded from: classes.dex */
public class GeodatabaseFeatureServiceTable extends GeodatabaseFeatureTable {
    private static final String L = "ATTACHMENTID";
    private static final String M = "REL_OBJECTID";
    private static final String N = "CONTENT_TYPE";
    private static final String O = "ATT_NAME";
    private static final String P = "REL_GLOBALID";
    private static final String f = "The extent parameter is invalid.";
    private static final String g = "The feature request mode cannot be changed once the table has been initialized or errored. Make sure you set the query mode before initializing the table.";
    private static final String h = "The spatial reference cannot be changed once the table has been initialized or errored. Make sure you set the spatial reference before initializing the table.";
    private static final String i = "The query parameter cannot be null.";
    private static final String j = "Cannot run a statistics query with populateFromService.";
    private static final String k = "populateFromService can only be called if the feature request mode is FeatureRequestMode.MANUAL_CACHE";
    private static final String l = "The table needs to be initialized before executing this operation.";
    private static final String m = "Couldn't retrieve layer service info - table initialization failed.";
    private static final String n = "Failed to initialize feature request mode.";
    private static final String o = "Operation not supported for FeatureRequestMode %s.";
    private static final String p = "Related table does not exist. Unable to import features.";
    private static final String q = "Failed to initialize related table.";
    private static final String r = "The out spatial reference of the QueryParameters does not match the spatial reference of the table.";
    private static final String s = "The out spatial reference of the RelatedQueryParameters does not match the spatial reference of the related table.";
    private static final String t = "Feature Layer";
    private static final String u = "Table";
    private static final String v = "relatedRecordGroups";
    private static final String w = "objectId";
    private static final String x = "relatedRecords";
    private boolean A;
    private String B;
    private String[] C;
    private double D;
    private SpatialReference E;
    private Envelope F;
    private final Envelope G;
    private final Object H;
    private Status I;
    private FeatureRequestMode J;
    private String K;
    private boolean Q;
    protected UserCredentials credentials;
    private AtomicBoolean y;
    private String z;

    /* loaded from: classes.dex */
    public enum FeatureRequestMode {
        UNDEFINED,
        MANUAL_CACHE,
        ON_INTERACTION_CACHE,
        ON_INTERACTION_NO_CACHE
    }

    /* loaded from: classes.dex */
    public enum Status {
        UNINITIALIZED,
        INITIALIZED,
        ERRORED
    }

    native void nativeAcknowledgeServiceAttachmentEdits(long j2, int i2, long j3, long[] jArr, long[] jArr2, long[] jArr3);

    native void nativeAcknowledgeServiceFeatureEdits(long j2, int i2, long j3, long[] jArr, long[] jArr2, long[] jArr3);

    native void nativeDeleteAllRows(long j2, int i2, boolean z);

    native boolean nativeFeatureHasNoAttachments(long j2, int i2, long j3);

    native String nativeGetDeletedAttachmentJSONMap(long j2, int i2);

    native String nativeGetInsertedAttachmentJSONMap(long j2, int i2);

    native String nativeGetUpdatedAttachmentJSONMap(long j2, int i2);

    native void nativeImportAttachmentByFilePath(long j2, int i2, long j3, long j4, String str);

    native void nativeImportAttachmentInfosByFilePath(long j2, int i2, long j3, String str);

    native void nativeImportFeaturesByFilePath(long j2, int i2, String str, boolean z, boolean z2, boolean z3);

    native long nativeStartUploadAttachments(long j2, int i2);

    native long nativeStartUploadFeatures(long j2, int i2);

    public GeodatabaseFeatureServiceTable(String str, int i2) {
        this.y = new AtomicBoolean(false);
        this.A = false;
        this.credentials = null;
        this.B = null;
        this.C = null;
        this.D = 1.0d;
        this.G = new Envelope();
        this.H = new Object();
        this.I = Status.UNINITIALIZED;
        this.J = FeatureRequestMode.UNDEFINED;
        this.K = null;
        this.Q = false;
        this.z = str;
        this.a = i2;
        this.credentials = null;
    }

    public GeodatabaseFeatureServiceTable(String str, UserCredentials userCredentials, int i2) {
        this(str, i2);
        this.credentials = userCredentials;
    }

    private GeodatabaseFeatureServiceTable(String str, UserCredentials userCredentials, int i2, Geodatabase geodatabase) {
        this(str, userCredentials, i2);
        this.b = geodatabase;
    }

    public FeatureRequestMode getFeatureRequestMode() {
        return this.J;
    }

    public void setFeatureRequestMode(FeatureRequestMode featureRequestMode) {
        if (this.I != Status.UNINITIALIZED) {
            throw new IllegalStateException(g);
        }
        this.J = featureRequestMode;
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable, com.esri.core.table.FeatureTable
    public Envelope getExtent() {
        return this.F;
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable, com.esri.core.table.FeatureTable
    public SpatialReference getSpatialReference() {
        if (this.I == Status.INITIALIZED) {
            return super.getSpatialReference();
        }
        return this.E;
    }

    public void setSpatialReference(SpatialReference spatialReference) {
        if (this.I != Status.UNINITIALIZED) {
            throw new IllegalStateException(h);
        }
        this.E = spatialReference;
    }

    public boolean isUsingAdvancedSymbols() {
        return this.A;
    }

    public void setUsingAdvancedSymbols(boolean z) {
        if (this.I == Status.INITIALIZED) {
            throw new RuntimeException("Cannot set this property once the GeodatabaseFeatureServiceTable is initialized");
        }
        this.A = z;
    }

    public Status getStatus() {
        return this.I;
    }

    public String getInitializationError() {
        return this.K;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(Exception exc) {
        if (exc.getMessage() != null) {
            this.K = exc.getMessage() + " (" + exc.getClass().getName() + " : " + exc.getStackTrace()[0].toString() + ")";
        } else {
            this.K = exc.getClass().getName() + " : " + exc.getStackTrace()[0].toString();
        }
        this.I = Status.ERRORED;
    }

    public Future<Status> initialize(final CallbackListener<Status> callbackListener) {
        return e.b.submit(new Callable<Status>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.1
            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public Status call() throws Exception {
                try {
                    if (GeodatabaseFeatureServiceTable.this.I == Status.UNINITIALIZED) {
                        GeodatabaseFeatureServiceTable.this.a();
                    }
                } catch (Error e) {
                    Exception exc = new Exception(e);
                    exc.fillInStackTrace();
                    GeodatabaseFeatureServiceTable.this.a(exc);
                    CallbackListener callbackListener2 = callbackListener;
                    if (callbackListener2 != null) {
                        callbackListener2.onError(exc);
                    }
                } catch (Exception e2) {
                    GeodatabaseFeatureServiceTable.this.a(e2);
                    CallbackListener callbackListener3 = callbackListener;
                    if (callbackListener3 != null) {
                        callbackListener3.onError(e2);
                    }
                }
                CallbackListener callbackListener4 = callbackListener;
                if (callbackListener4 != null) {
                    callbackListener4.onCallback(GeodatabaseFeatureServiceTable.this.I);
                }
                return GeodatabaseFeatureServiceTable.this.I;
            }
        });
    }

    public Status initialize() {
        if (this.I == Status.UNINITIALIZED) {
            try {
                a();
            } catch (Exception e) {
                a(e);
            }
        }
        return this.I;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a() throws Exception {
        if (this.y.compareAndSet(false, true)) {
            AutoCloseable autoCloseable = null;
            try {
                w wVar = new w();
                wVar.a(this.A);
                String execute = new x(wVar, getServiceUrl(), this.credentials, null).execute();
                if (this.b == null) {
                    this.b = new Geodatabase(execute, this.z, File.createTempFile("FeatureServiceTable", ".geodatabase", Geodatabase.a()).getAbsolutePath(), this.E, this.credentials);
                } else if (!this.b.a(this.a)) {
                    this.b.a(execute, this.z, this.E);
                }
                String nativeGetSchema = nativeGetSchema(getHandle(), this.a);
                JsonFactory jsonFactory = new JsonFactory();
                this.c = LayerServiceInfo.fromJson(jsonFactory.createJsonParser(nativeGetSchema));
                if (this.c == null) {
                    throw new IllegalStateException(m);
                }
                this.d = this.c.getEditFieldsInfo();
                JsonParser createJsonParser = jsonFactory.createJsonParser(nativeGetSchema);
                this.e = Relationship.listFromJson(createJsonParser, this.b);
                this.d = this.c.getEditFieldsInfo();
                Geodatabase geodatabase = this.b;
                UserCredentials userCredentials = this.credentials;
                geodatabase.a(userCredentials != null ? userCredentials.getUserName() : "", this.d != null ? this.d.getRealm() : "");
                MapGeometry extent = this.c.getExtent();
                if (extent != null && extent.getGeometry() != null) {
                    this.F = new Envelope();
                    extent.getGeometry().queryEnvelope(this.F);
                    if (this.E != null) {
                        this.F = (Envelope) GeometryEngine.project(this.F, extent.getSpatialReference(), this.E);
                    }
                }
                c();
                b();
                this.I = Status.INITIALIZED;
                if (createJsonParser != null) {
                    createJsonParser.close();
                }
            } catch (Throwable th) {
                if (0 != 0) {
                    autoCloseable.close();
                }
                throw th;
            }
        }
    }

    private void b() {
        if (this.e == null || this.e.size() == 0) {
            return;
        }
        for (Relationship relationship : this.e) {
            GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable = new GeodatabaseFeatureServiceTable(this.z, this.credentials, relationship.a(), this.b);
            geodatabaseFeatureServiceTable.setFeatureRequestMode(this.J);
            relationship.a(geodatabaseFeatureServiceTable);
        }
    }

    private void c() {
        String type = this.c.getType();
        if (this.J == FeatureRequestMode.UNDEFINED) {
            if (t.equals(type)) {
                this.J = FeatureRequestMode.ON_INTERACTION_CACHE;
            } else if (u.equals(type)) {
                this.J = FeatureRequestMode.MANUAL_CACHE;
            }
        }
        if (this.J == FeatureRequestMode.UNDEFINED) {
            throw new IllegalStateException(n);
        }
    }

    String a(long[] jArr) {
        if (jArr == null || jArr.length == 0) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(getObjectIdField());
        sb.append(" NOT IN (");
        int length = jArr.length < 2000 ? jArr.length : 2000;
        int i2 = 0;
        while (true) {
            int i3 = length - 1;
            if (i2 < i3) {
                sb.append(jArr[i2] + ",");
                i2++;
            } else {
                sb.append(jArr[i3]);
                sb.append(")");
                return sb.toString();
            }
        }
    }

    public Future<Void> fetchFeatures(final long[] jArr, final double[] dArr, double d) {
        if (dArr != null && dArr.length != 4) {
            throw new IllegalArgumentException(f);
        }
        synchronized (this.G) {
            if (dArr != null) {
                this.G.setCoords(dArr[0], dArr[1], dArr[2], dArr[3]);
            }
        }
        try {
            return e.c.submit(new Callable<Void>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.4
                /* JADX WARN: Not initialized variable reg: 3, insn: 0x013e: MOVE  (r2 I:??[OBJECT, ARRAY]) = (r3 I:??[OBJECT, ARRAY]), block:B:71:0x013e */
                @Override // java.util.concurrent.Callable
                /* renamed from: a */
                public Void call() {
                    InputStream inputStream;
                    InputStream inputStream2;
                    InputStream inputStream3 = null;
                    try {
                        try {
                            try {
                                i iVar = new i();
                                double[] dArr2 = dArr;
                                boolean z = true;
                                if (dArr2 != null) {
                                    iVar.a(GeodatabaseFeatureServiceTable.this.a(new Envelope(dArr2[0], dArr2[1], dArr2[2], dArr2[3])));
                                }
                                if (GeodatabaseFeatureServiceTable.this.E != null) {
                                    iVar.c(GeodatabaseFeatureServiceTable.this.E);
                                    iVar.b(GeodatabaseFeatureServiceTable.this.E);
                                }
                                iVar.a(SpatialRelationship.INTERSECTS);
                                if (GeodatabaseFeatureServiceTable.this.C == null || GeodatabaseFeatureServiceTable.this.C.length <= 0) {
                                    iVar.a(new String[]{"*"});
                                } else {
                                    iVar.a(GeodatabaseFeatureServiceTable.this.C);
                                }
                                String a2 = GeodatabaseFeatureServiceTable.this.J == FeatureRequestMode.ON_INTERACTION_CACHE ? GeodatabaseFeatureServiceTable.this.a(jArr) : null;
                                if (GeodatabaseFeatureServiceTable.this.B != null && !GeodatabaseFeatureServiceTable.this.B.isEmpty()) {
                                    if (a2 == null || a2.isEmpty()) {
                                        a2 = GeodatabaseFeatureServiceTable.this.B;
                                    } else {
                                        a2 = GeodatabaseFeatureServiceTable.this.B + " AND " + a2;
                                    }
                                }
                                iVar.a(a2);
                                String serviceUrl = GeodatabaseFeatureServiceTable.this.getServiceUrl();
                                if (Thread.currentThread().isInterrupted()) {
                                    inputStream2 = null;
                                } else {
                                    inputStream2 = new p(iVar, serviceUrl, GeodatabaseFeatureServiceTable.this.credentials).execute();
                                    try {
                                        if (!Thread.currentThread().isInterrupted()) {
                                            GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable = GeodatabaseFeatureServiceTable.this;
                                            int i2 = geodatabaseFeatureServiceTable.a;
                                            if (GeodatabaseFeatureServiceTable.this.J != FeatureRequestMode.ON_INTERACTION_NO_CACHE) {
                                                z = false;
                                            }
                                            geodatabaseFeatureServiceTable.a(inputStream2, i2, z, false);
                                        }
                                    } catch (InterruptedIOException e) {
                                        e = e;
                                        if (e.getCause() instanceof InterruptedException) {
                                            Thread.currentThread().interrupt();
                                        }
                                        if (inputStream2 != null) {
                                            inputStream2.close();
                                        }
                                        return null;
                                    } catch (InterruptedException unused) {
                                        Thread.currentThread().interrupt();
                                        if (inputStream2 != null) {
                                            inputStream2.close();
                                        }
                                        return null;
                                    } catch (Exception e2) {
                                        e = e2;
                                        e.printStackTrace();
                                        if (inputStream2 != null) {
                                            inputStream2.close();
                                        }
                                        return null;
                                    }
                                }
                            } catch (InterruptedIOException e3) {
                                e = e3;
                                inputStream2 = null;
                            } catch (InterruptedException unused2) {
                                inputStream2 = null;
                            } catch (Exception e4) {
                                e = e4;
                                inputStream2 = null;
                            } catch (Throwable th) {
                                th = th;
                                Throwable th2 = th;
                                if (inputStream3 != null) {
                                    try {
                                        inputStream3.close();
                                    } catch (IOException e5) {
                                        e5.printStackTrace();
                                    }
                                }
                                throw th2;
                            }
                            if (inputStream2 != null) {
                                inputStream2.close();
                            }
                        } catch (IOException e6) {
                            e6.printStackTrace();
                        }
                        return null;
                    } catch (Throwable th3) {
                        th = th3;
                        inputStream3 = inputStream;
                    }
                }
            });
        } catch (RejectedExecutionException unused) {
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public Envelope a(Envelope envelope) {
        Point center = envelope.getCenter();
        int i2 = (this.D > 1.0d ? 1 : (this.D == 1.0d ? 0 : -1));
        double width = envelope.getWidth();
        if (i2 > 0) {
            width *= this.D;
        }
        int i3 = (this.D > 1.0d ? 1 : (this.D == 1.0d ? 0 : -1));
        double height = envelope.getHeight();
        if (i3 > 0) {
            height *= this.D;
        }
        return new Envelope(center, width, height);
    }

    public Future<Boolean> populateFromService(final QueryParameters queryParameters, final boolean z, final CallbackListener<Boolean> callbackListener) {
        if (queryParameters == null) {
            throw new IllegalArgumentException(i);
        }
        if (isAggregateQuery(queryParameters)) {
            throw new IllegalArgumentException(j);
        }
        if (this.I != Status.INITIALIZED) {
            throw new IllegalStateException(l);
        }
        if (this.J != FeatureRequestMode.MANUAL_CACHE) {
            throw new IllegalStateException(k);
        }
        queryParameters.setOutSpatialReference(getSpatialReference());
        checkOutFields(queryParameters);
        return e.c.submit(new Callable<Boolean>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.5
            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public Boolean call() throws Exception {
                Boolean bool = Boolean.TRUE;
                try {
                    try {
                        if (!Thread.currentThread().isInterrupted()) {
                            GeodatabaseFeatureServiceTable.this.a(queryParameters, z, true);
                            return bool;
                        }
                        throw new InterruptedException();
                    } catch (Exception e) {
                        Boolean bool2 = Boolean.FALSE;
                        CallbackListener callbackListener2 = callbackListener;
                        if (callbackListener2 != null) {
                            callbackListener2.onError(e);
                        }
                        throw e;
                    }
                } finally {
                    CallbackListener callbackListener3 = callbackListener;
                    if (callbackListener3 != null) {
                        callbackListener3.onCallback(bool);
                    }
                }
            }
        });
    }

    private void a(QueryParameters queryParameters) {
        SpatialReference spatialReference = getSpatialReference();
        if (spatialReference == null || queryParameters == null) {
            return;
        }
        SpatialReference outSpatialReference = queryParameters.getOutSpatialReference();
        if (outSpatialReference == null) {
            queryParameters.setOutSpatialReference(spatialReference);
        } else if (!outSpatialReference.equals(spatialReference)) {
            throw new IllegalArgumentException(r);
        }
    }

    private void a(RelatedQueryParameters relatedQueryParameters, GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable) {
        SpatialReference spatialReference = geodatabaseFeatureServiceTable.getSpatialReference();
        if (spatialReference == null || relatedQueryParameters == null) {
            return;
        }
        SpatialReference outSpatialReference = relatedQueryParameters.getOutSpatialReference();
        if (outSpatialReference == null) {
            relatedQueryParameters.setOutSpatialReference(spatialReference);
        } else if (!outSpatialReference.equals(spatialReference)) {
            throw new IllegalArgumentException(s);
        }
    }

    private void a(RelatedQueryParameters relatedQueryParameters) {
        if (relatedQueryParameters != null) {
            String[] outFields = relatedQueryParameters.getOutFields();
            if (outFields == null || outFields.length == 0) {
                relatedQueryParameters.setOutFields(new String[]{"*"});
            }
        }
    }

    public void clearCache() {
        nativeDeleteAllRows(getHandle(), this.a, true);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(QueryParameters queryParameters, boolean z, boolean z2) throws Exception {
        InputStream inputStream = null;
        try {
            inputStream = new p(i.a(queryParameters), getServiceUrl(), this.credentials).execute();
            a(inputStream, this.a, z, z2);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public Map<Long, FeatureResult> a(RelatedQueryParameters relatedQueryParameters, GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable, boolean z, boolean z2) throws Exception {
        JsonParser jsonParser;
        ByteArrayInputStream byteArrayInputStream;
        Map<Long, FeatureResult> a2;
        JsonParser jsonParser2;
        InputStream inputStream = null;
        ByteArrayInputStream byteArrayInputStream2 = null;
        JsonParser jsonParser3 = null;
        try {
            InputStream execute = new q(com.esri.core.internal.tasks.ags.c.e.a(relatedQueryParameters), getServiceUrl(), this.credentials).execute();
            if (execute != null) {
                try {
                    byteArrayInputStream = new ByteArrayInputStream(a(execute).getBytes("UTF-8"));
                    try {
                        a(byteArrayInputStream, geodatabaseFeatureServiceTable.a, z, z2);
                        execute.reset();
                        jsonParser3 = d.a(execute);
                        a2 = a(jsonParser3, geodatabaseFeatureServiceTable, relatedQueryParameters.getOutSpatialReference());
                        jsonParser2 = jsonParser3;
                        byteArrayInputStream2 = byteArrayInputStream;
                    } catch (Throwable th) {
                        th = th;
                        jsonParser = jsonParser3;
                        inputStream = execute;
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        if (byteArrayInputStream != null) {
                            byteArrayInputStream.close();
                        }
                        if (jsonParser != null) {
                            jsonParser.close();
                        }
                        throw th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    jsonParser = null;
                    byteArrayInputStream = null;
                }
            } else {
                jsonParser2 = null;
                a2 = null;
            }
            if (execute != null) {
                execute.close();
            }
            if (byteArrayInputStream2 != null) {
                byteArrayInputStream2.close();
            }
            if (jsonParser2 != null) {
                jsonParser2.close();
            }
            return a2;
        } catch (Throwable th3) {
            th = th3;
            jsonParser = null;
            byteArrayInputStream = null;
        }
    }

    private Map<Long, FeatureResult> a(JsonParser jsonParser, GeodatabaseFeatureTable geodatabaseFeatureTable, SpatialReference spatialReference) throws Exception {
        HashMap hashMap = new HashMap();
        if (jsonParser == null || !d.c(jsonParser)) {
            return null;
        }
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if (v.equals(currentName)) {
                if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        ArrayList<com.esri.core.internal.tasks.ags.c.a> arrayList = new ArrayList();
                        long j2 = -1;
                        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                            String currentName2 = jsonParser.getCurrentName();
                            jsonParser.nextToken();
                            if (w.equals(currentName2)) {
                                j2 = jsonParser.getLongValue();
                            } else if (x.equals(currentName2)) {
                                if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                        arrayList.add(com.esri.core.internal.tasks.ags.c.a.a(jsonParser, spatialReference, geodatabaseFeatureTable.getObjectIdField()));
                                    }
                                }
                            } else {
                                jsonParser.skipChildren();
                            }
                        }
                        if (j2 != -1) {
                            long[] jArr = new long[arrayList.size()];
                            int i2 = 0;
                            for (com.esri.core.internal.tasks.ags.c.a aVar : arrayList) {
                                jArr[i2] = aVar.getId();
                                i2++;
                            }
                            hashMap.put(Long.valueOf(j2), new GeodatabaseFeatureTable.b(geodatabaseFeatureTable, jArr, spatialReference, geodatabaseFeatureTable.getDisplayField(), geodatabaseFeatureTable.getObjectIdField(), geodatabaseFeatureTable.getFields()));
                        }
                    }
                }
            } else {
                jsonParser.skipChildren();
            }
        }
        return hashMap;
    }

    private String a(InputStream inputStream) throws Exception {
        JsonParser jsonParser;
        StringBuilder sb = new StringBuilder("{ \"features\": [");
        ArrayList<String> arrayList = new ArrayList();
        try {
            jsonParser = d.a(inputStream);
            if (jsonParser != null) {
                try {
                    if (d.c(jsonParser)) {
                        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                            String currentName = jsonParser.getCurrentName();
                            jsonParser.nextToken();
                            if (v.equals(currentName)) {
                                if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                        arrayList.addAll(a.a(jsonParser));
                                    }
                                }
                            } else {
                                jsonParser.skipChildren();
                            }
                        }
                    }
                } catch (Throwable th) {
                    th = th;
                    if (jsonParser != null) {
                        jsonParser.close();
                    }
                    throw th;
                }
            }
            boolean z = true;
            for (String str : arrayList) {
                if (!z) {
                    sb.append(",");
                }
                sb.append(str);
                z = false;
            }
            sb.append("] }");
            if (jsonParser != null) {
                jsonParser.close();
            }
            return sb.toString();
        } catch (Throwable th2) {
            th = th2;
            jsonParser = null;
        }
    }

    public Future<List<GeodatabaseEditError>> applyEdits(CallbackListener<List<GeodatabaseEditError>> callbackListener) {
        return a(getAddedFeatures(), getUpdatedFeatures(), getDeletedFeatures(), callbackListener);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public ArrayList<Long> a(List<Long> list, List<Feature> list2, List<Feature> list3, List<Feature> list4) {
        ArrayList<Long> arrayList = new ArrayList<>();
        if (list2 != null) {
            for (Feature feature : list2) {
                arrayList.add(Long.valueOf(feature.getId()));
            }
        }
        if (list3 != null) {
            for (Feature feature2 : list3) {
                arrayList.add(Long.valueOf(feature2.getId()));
            }
        }
        if (list4 != null) {
            for (Feature feature3 : list4) {
                arrayList.add(Long.valueOf(feature3.getId()));
            }
        }
        if (list != null) {
            for (Long l2 : list) {
                arrayList.remove(l2);
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(long j2, List<Long> list, List<Long> list2, List<Long> list3) {
        long[] jArr = new long[list.size()];
        long[] jArr2 = new long[list2.size()];
        for (int i2 = 0; i2 != list.size(); i2++) {
            jArr[i2] = list.get(i2).longValue();
            jArr2[i2] = list2.get(i2).longValue();
        }
        long[] jArr3 = new long[list3.size()];
        for (int i3 = 0; i3 != list3.size(); i3++) {
            jArr3[i3] = list3.get(i3).longValue();
        }
        nativeAcknowledgeServiceFeatureEdits(getHandle(), this.a, j2, jArr, jArr2, jArr3);
    }

    private Future<List<GeodatabaseEditError>> a(final List<Feature> list, final List<Feature> list2, final List<Feature> list3, final CallbackListener<List<GeodatabaseEditError>> callbackListener) {
        final long nativeStartUploadFeatures = nativeStartUploadFeatures(getHandle(), this.a);
        try {
            return e.c.submit(new Callable<List<GeodatabaseEditError>>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.6
                /* JADX WARN: Code restructure failed: missing block: B:37:0x01dd, code lost:
                    if (r0 != null) goto L50;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:46:0x01ff, code lost:
                    if (r0 == null) goto L49;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:50:0x021e, code lost:
                    if (r0 == null) goto L49;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:51:0x0220, code lost:
                    r0.onCallback(r8);
                 */
                /* JADX WARN: Code restructure failed: missing block: B:52:0x0223, code lost:
                    return r8;
                 */
                @Override // java.util.concurrent.Callable
                /* renamed from: a */
                /*
                    Code decompiled incorrectly, please refer to instructions dump.
                    To view partially-correct code enable 'Show inconsistent code' option in preferences
                */
                public java.util.List<com.esri.core.geodatabase.GeodatabaseEditError> call() throws java.lang.Exception {
                    /*
                        Method dump skipped, instructions count: 565
                        To view this dump change 'Code comments level' option to 'DEBUG'
                    */
                    throw new UnsupportedOperationException("Method not decompiled: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.AnonymousClass6.call():java.util.List");
                }
            });
        } catch (RejectedExecutionException e) {
            a(nativeStartUploadFeatures, new ArrayList(), new ArrayList(), a((List<Long>) null, list, list2, list3));
            if (callbackListener != null) {
                callbackListener.onError(e);
                callbackListener.onCallback(null);
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public ArrayList<Long> b(List<Long> list, List<Map<String, Object>> list2, List<Map<String, Object>> list3, List<Map<String, Object>> list4) {
        ArrayList<Long> arrayList = new ArrayList<>();
        if (list2 != null) {
            for (Map<String, Object> map : list2) {
                arrayList.add((Long) map.get(L));
            }
        }
        if (list3 != null) {
            for (Map<String, Object> map2 : list3) {
                arrayList.add((Long) map2.get(L));
            }
        }
        if (list4 != null) {
            for (Map<String, Object> map3 : list4) {
                arrayList.add((Long) map3.get(L));
            }
        }
        if (list != null) {
            for (Long l2 : list) {
                arrayList.remove(l2);
            }
        }
        return arrayList;
    }

    public Future<List<GeodatabaseEditError>> applyAttachmentEdits(final CallbackListener<List<GeodatabaseEditError>> callbackListener) {
        final List<Map<String, Object>> addedAttachments = getAddedAttachments();
        final List<Map<String, Object>> updatedAttachments = getUpdatedAttachments();
        final List<Map<String, Object>> deletedAttachments = getDeletedAttachments();
        final long nativeStartUploadAttachments = nativeStartUploadAttachments(getHandle(), this.a);
        try {
            return e.c.submit(new Callable<List<GeodatabaseEditError>>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.7
                /* JADX WARN: Code restructure failed: missing block: B:14:0x0079, code lost:
                    if (r0 != null) goto L17;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:15:0x007b, code lost:
                    r0.onCallback(r9);
                 */
                /* JADX WARN: Code restructure failed: missing block: B:25:0x00a4, code lost:
                    if (r0 == null) goto L18;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:30:0x00c5, code lost:
                    if (r0 == null) goto L18;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:35:0x00e6, code lost:
                    if (r0 == null) goto L18;
                 */
                /* JADX WARN: Code restructure failed: missing block: B:37:0x00e9, code lost:
                    return r9;
                 */
                @Override // java.util.concurrent.Callable
                /* renamed from: a */
                /*
                    Code decompiled incorrectly, please refer to instructions dump.
                    To view partially-correct code enable 'Show inconsistent code' option in preferences
                */
                public java.util.List<com.esri.core.geodatabase.GeodatabaseEditError> call() {
                    /*
                        Method dump skipped, instructions count: 255
                        To view this dump change 'Code comments level' option to 'DEBUG'
                    */
                    throw new UnsupportedOperationException("Method not decompiled: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.AnonymousClass7.call():java.util.List");
                }
            });
        } catch (RejectedExecutionException e) {
            b(nativeStartUploadAttachments, new ArrayList(), new ArrayList(), b((List<Long>) null, addedAttachments, updatedAttachments, deletedAttachments));
            if (callbackListener != null) {
                callbackListener.onError(e);
                callbackListener.onCallback(null);
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void b(long j2, List<Long> list, List<Long> list2, List<Long> list3) {
        long[] jArr = new long[list.size()];
        long[] jArr2 = new long[list2.size()];
        for (int i2 = 0; i2 != list.size(); i2++) {
            jArr[i2] = list.get(i2).longValue();
            jArr2[i2] = list2.get(i2).longValue();
        }
        long[] jArr3 = new long[list3.size()];
        for (int i3 = 0; i3 != list3.size(); i3++) {
            jArr3[i3] = list3.get(i3).longValue();
        }
        nativeAcknowledgeServiceAttachmentEdits(getHandle(), this.a, j2, jArr, jArr2, jArr3);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public List<GeodatabaseEditError> a(List<Map<String, Object>> list, ArrayList<Long> arrayList, ArrayList<Long> arrayList2, ArrayList<Long> arrayList3) throws Exception {
        ArrayList arrayList4 = new ArrayList();
        for (Map<String, Object> map : list) {
            Long l2 = (Long) map.get(L);
            Long l3 = (Long) map.get(M);
            String str = (String) map.get(N);
            String str2 = (String) map.get(O);
            String str3 = (String) map.get(P);
            ByteArrayInputStream retrieveAttachment = retrieveAttachment(l3.longValue(), l2.longValue());
            if (retrieveAttachment != null) {
                c cVar = new c();
                cVar.a(l3.longValue());
                cVar.a(retrieveAttachment, str2, str);
                FeatureEditResult execute = new com.esri.core.internal.tasks.ags.a(cVar, getServiceUrl(), this.credentials).execute();
                if (execute != null && !execute.isSuccess()) {
                    arrayList4.add(new GeodatabaseEditError(l3.longValue(), str3, execute.getObjectId(), execute.getGlobalId(), GeodatabaseEditError.EditOperation.ADD, execute.getError(), this.a, getTableName()));
                    arrayList3.add(l2);
                } else {
                    arrayList.add(l2);
                    arrayList2.add(Long.valueOf(execute.getObjectId()));
                }
            }
        }
        return arrayList4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public List<GeodatabaseEditError> b(List<Map<String, Object>> list, ArrayList<Long> arrayList, ArrayList<Long> arrayList2, ArrayList<Long> arrayList3) throws Exception {
        ArrayList arrayList4 = new ArrayList();
        for (Map<String, Object> map : list) {
            Long l2 = (Long) map.get(L);
            Long l3 = (Long) map.get(M);
            String str = (String) map.get(N);
            String str2 = (String) map.get(O);
            String str3 = (String) map.get(P);
            ByteArrayInputStream retrieveAttachment = retrieveAttachment(l3.longValue(), l2.longValue());
            if (retrieveAttachment != null) {
                FeatureEditResult execute = new f(new g(l3.longValue(), l2.longValue(), retrieveAttachment, str2, str), getServiceUrl(), this.credentials).execute();
                if (execute != null && !execute.isSuccess()) {
                    arrayList4.add(new GeodatabaseEditError(l3.longValue(), str3, execute.getObjectId(), execute.getGlobalId(), GeodatabaseEditError.EditOperation.UPDATE, execute.getError(), this.a, getTableName()));
                    arrayList3.add(l2);
                } else {
                    arrayList.add(l2);
                    arrayList2.add(Long.valueOf(execute.getObjectId()));
                }
            }
        }
        return arrayList4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public List<GeodatabaseEditError> c(List<Map<String, Object>> list, ArrayList<Long> arrayList, ArrayList<Long> arrayList2, ArrayList<Long> arrayList3) throws Exception {
        int i2;
        int i3;
        FeatureEditResult[] featureEditResultArr;
        GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable = this;
        ArrayList arrayList4 = new ArrayList();
        for (Map<String, Object> map : list) {
            Long l2 = (Long) map.get(L);
            Long l3 = (Long) map.get(M);
            String str = (String) map.get(P);
            c cVar = new c();
            cVar.a(new long[]{l2.longValue()});
            cVar.a(l3.longValue());
            FeatureEditResult[] execute = new b(cVar, getServiceUrl(), geodatabaseFeatureServiceTable.credentials).execute();
            int length = execute.length;
            int i4 = 0;
            while (i4 < length) {
                FeatureEditResult featureEditResult = execute[i4];
                if (!featureEditResult.isSuccess()) {
                    i2 = i4;
                    i3 = length;
                    featureEditResultArr = execute;
                    arrayList4.add(new GeodatabaseEditError(l3.longValue(), str, featureEditResult.getObjectId(), featureEditResult.getGlobalId(), GeodatabaseEditError.EditOperation.DELETE, featureEditResult.getError(), geodatabaseFeatureServiceTable.a, getTableName()));
                    arrayList3.add(l2);
                } else {
                    i2 = i4;
                    i3 = length;
                    featureEditResultArr = execute;
                    arrayList.add(l2);
                    arrayList2.add(Long.valueOf(featureEditResult.getObjectId()));
                }
                i4 = i2 + 1;
                geodatabaseFeatureServiceTable = this;
                length = i3;
                execute = featureEditResultArr;
            }
            geodatabaseFeatureServiceTable = this;
        }
        return arrayList4;
    }

    public void setBufferFactor(double d) {
        this.D = d;
    }

    public double getBufferFactor() {
        return this.D;
    }

    public void refreshFeatures() {
        clearCache();
        synchronized (this.G) {
            if (!this.G.isEmpty()) {
                fetchFeatures(null, new double[]{this.G.getXMin(), this.G.getYMin(), this.G.getXMax(), this.G.getYMax()}, Utils.DOUBLE_EPSILON);
            }
        }
    }

    public void setDefinitionExpression(String str) {
        this.B = str;
    }

    public String getDefinitionExpression() {
        return this.B;
    }

    public void setOutFields(String[] strArr) {
        if (this.I != Status.INITIALIZED) {
            throw new IllegalStateException(l);
        }
        if (strArr == null || strArr.length == 0) {
            this.C = null;
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            arrayList.add(str.trim());
        }
        String objectIdField = getObjectIdField();
        if (com.esri.core.internal.util.g.b(objectIdField) && !arrayList.contains(objectIdField) && !arrayList.contains("*")) {
            arrayList.add(objectIdField);
        }
        this.C = (String[]) arrayList.toArray(new String[0]);
    }

    public String[] getOutFields() {
        return this.C;
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable, com.esri.core.table.FeatureTable
    public Future<FeatureResult> queryFeatures(QueryParameters queryParameters, CallbackListener<FeatureResult> callbackListener) {
        if (this.I != Status.INITIALIZED) {
            throw new IllegalStateException(l);
        }
        queryParameters.setOutSpatialReference(getSpatialReference());
        checkOutFields(queryParameters);
        int i2 = AnonymousClass3.a[this.J.ordinal()];
        if (i2 != 1) {
            if (i2 != 2) {
                if (i2 == 3) {
                    return a(queryParameters, true, true, callbackListener);
                }
                throw new UnsupportedOperationException(String.format(o, this.J));
            } else if (b(queryParameters)) {
                return super.queryFeatures(queryParameters, callbackListener);
            } else {
                return a(queryParameters, false, false, callbackListener);
            }
        }
        return super.queryFeatures(queryParameters, callbackListener);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable$3  reason: invalid class name */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[FeatureRequestMode.values().length];
            a = iArr;
            try {
                iArr[FeatureRequestMode.MANUAL_CACHE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[FeatureRequestMode.ON_INTERACTION_CACHE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[FeatureRequestMode.ON_INTERACTION_NO_CACHE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    private boolean b(QueryParameters queryParameters) {
        String[] strArr;
        return queryParameters != null && a(queryParameters.getGeometry(), queryParameters.getInSpatialReference()) && (!com.esri.core.internal.util.g.b(queryParameters.getWhere()) || (strArr = this.C) == null || strArr.length == 0);
    }

    private boolean a(Geometry geometry, SpatialReference spatialReference) {
        Envelope envelope = this.G;
        if (envelope == null || envelope.isEmpty() || geometry == null) {
            return false;
        }
        SpatialReference spatialReference2 = getSpatialReference();
        if (spatialReference != null && !spatialReference.equals(spatialReference2)) {
            geometry = GeometryEngine.project(geometry, spatialReference, spatialReference2);
        }
        return GeometryEngine.within(geometry, a(this.G), spatialReference2);
    }

    private Future<FeatureResult> a(final QueryParameters queryParameters, final boolean z, final boolean z2, final CallbackListener<FeatureResult> callbackListener) {
        return e.b.submit(new Callable<FeatureResult>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.8
            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public FeatureResult call() throws Exception {
                try {
                    try {
                        if (!Thread.currentThread().isInterrupted()) {
                            GeodatabaseFeatureServiceTable.this.a(queryParameters, z, z2);
                            FeatureResult queryFeaturesInner = GeodatabaseFeatureServiceTable.super.queryFeaturesInner(queryParameters);
                            CallbackListener callbackListener2 = callbackListener;
                            if (callbackListener2 != null) {
                                callbackListener2.onCallback(queryFeaturesInner);
                            }
                            return queryFeaturesInner;
                        }
                        throw new InterruptedException();
                    } catch (Exception e) {
                        CallbackListener callbackListener3 = callbackListener;
                        if (callbackListener3 != null) {
                            callbackListener3.onError(e);
                        }
                        throw e;
                    }
                } catch (Throwable th) {
                    CallbackListener callbackListener4 = callbackListener;
                    if (callbackListener4 != null) {
                        callbackListener4.onCallback(null);
                    }
                    throw th;
                }
            }
        });
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable, com.esri.core.table.FeatureTable
    public Future<long[]> queryIds(QueryParameters queryParameters, CallbackListener<long[]> callbackListener) {
        if (this.I != Status.INITIALIZED) {
            throw new IllegalStateException(l);
        }
        queryParameters.setOutSpatialReference(getSpatialReference());
        checkOutFields(queryParameters);
        int i2 = AnonymousClass3.a[this.J.ordinal()];
        if (i2 != 1) {
            if (i2 != 2) {
                if (i2 == 3) {
                    return b(queryParameters, true, true, callbackListener);
                }
                throw new UnsupportedOperationException(String.format(o, this.J));
            } else if (b(queryParameters)) {
                return super.queryIds(queryParameters, callbackListener);
            } else {
                return b(queryParameters, false, false, callbackListener);
            }
        }
        return super.queryIds(queryParameters, callbackListener);
    }

    private Future<long[]> b(final QueryParameters queryParameters, final boolean z, final boolean z2, final CallbackListener<long[]> callbackListener) {
        return e.b.submit(new Callable<long[]>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.9
            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public long[] call() throws Exception {
                try {
                    try {
                        if (!Thread.currentThread().isInterrupted()) {
                            GeodatabaseFeatureServiceTable.this.a(queryParameters, z, z2);
                            long[] nativeQueryIds = LocalGDBUtil.nativeQueryIds(GeodatabaseFeatureServiceTable.this.getHandle(), GeodatabaseFeatureServiceTable.this.a, queryParameters.toJSON());
                            CallbackListener callbackListener2 = callbackListener;
                            if (callbackListener2 != null) {
                                callbackListener2.onCallback(nativeQueryIds);
                            }
                            return nativeQueryIds;
                        }
                        throw new InterruptedException();
                    } catch (Exception e) {
                        CallbackListener callbackListener3 = callbackListener;
                        if (callbackListener3 != null) {
                            callbackListener3.onError(e);
                        }
                        throw e;
                    }
                } catch (Throwable th) {
                    CallbackListener callbackListener4 = callbackListener;
                    if (callbackListener4 != null) {
                        callbackListener4.onCallback(null);
                    }
                    throw th;
                }
            }
        });
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable
    public Future<List<AttachmentInfo>> queryAttachmentInfos(final long j2, final CallbackListener<List<AttachmentInfo>> callbackListener) {
        try {
            return e.b.submit(new Callable<List<AttachmentInfo>>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.10
                @Override // java.util.concurrent.Callable
                /* renamed from: a */
                public List<AttachmentInfo> call() throws Exception {
                    List<AttachmentInfo> queryAttachmentInfos;
                    try {
                        GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable = GeodatabaseFeatureServiceTable.this;
                        if (geodatabaseFeatureServiceTable.nativeFeatureHasNoAttachments(geodatabaseFeatureServiceTable.getHandle(), GeodatabaseFeatureServiceTable.this.a, j2)) {
                            queryAttachmentInfos = new ArrayList<>();
                        } else {
                            queryAttachmentInfos = GeodatabaseFeatureServiceTable.this.queryAttachmentInfos(j2);
                        }
                    } catch (InterruptedIOException e) {
                        if (e.getCause() instanceof InterruptedException) {
                            Thread.currentThread().interrupt();
                        }
                    } catch (InterruptedException unused) {
                        Thread.currentThread().interrupt();
                    } catch (Exception e2) {
                        CallbackListener callbackListener2 = callbackListener;
                        if (callbackListener2 != null) {
                            callbackListener2.onError(e2);
                            callbackListener.onCallback(null);
                        }
                    }
                    if (queryAttachmentInfos != null) {
                        CallbackListener callbackListener3 = callbackListener;
                        if (callbackListener3 != null) {
                            callbackListener3.onCallback(queryAttachmentInfos);
                        }
                        return queryAttachmentInfos;
                    }
                    c cVar = new c();
                    cVar.a(j2);
                    com.esri.core.internal.tasks.ags.e eVar = new com.esri.core.internal.tasks.ags.e(cVar, GeodatabaseFeatureServiceTable.this.getServiceUrl(), GeodatabaseFeatureServiceTable.this.credentials);
                    if (!Thread.currentThread().isInterrupted()) {
                        GeodatabaseFeatureServiceTable.this.a(j2, eVar.execute());
                        List<AttachmentInfo> queryAttachmentInfos2 = GeodatabaseFeatureServiceTable.this.queryAttachmentInfos(j2);
                        CallbackListener callbackListener4 = callbackListener;
                        if (callbackListener4 != null) {
                            callbackListener4.onCallback(queryAttachmentInfos2);
                        }
                        return queryAttachmentInfos2;
                    }
                    return null;
                }
            });
        } catch (RejectedExecutionException unused) {
            return null;
        }
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable
    public Future<InputStream> retrieveAttachment(final long j2, final long j3, final CallbackListener<InputStream> callbackListener) {
        try {
            return e.b.submit(new Callable<InputStream>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.11
                @Override // java.util.concurrent.Callable
                /* renamed from: a */
                public InputStream call() throws Exception {
                    ByteArrayInputStream retrieveAttachment;
                    try {
                        retrieveAttachment = GeodatabaseFeatureServiceTable.this.retrieveAttachment(j2, j3);
                    } catch (InterruptedIOException e) {
                        if (e.getCause() instanceof InterruptedException) {
                            Thread.currentThread().interrupt();
                        }
                    } catch (InterruptedException unused) {
                        Thread.currentThread().interrupt();
                    } catch (Exception e2) {
                        CallbackListener callbackListener2 = callbackListener;
                        if (callbackListener2 != null) {
                            callbackListener2.onError(e2);
                            callbackListener.onCallback(null);
                        }
                    }
                    if (retrieveAttachment != null) {
                        CallbackListener callbackListener3 = callbackListener;
                        if (callbackListener3 != null) {
                            callbackListener3.onCallback(retrieveAttachment);
                        }
                        return retrieveAttachment;
                    }
                    HashMap hashMap = new HashMap();
                    hashMap.put("f", "json");
                    if (!Thread.currentThread().isInterrupted()) {
                        GeodatabaseFeatureServiceTable.this.a(j2, j3, com.esri.core.internal.io.handler.a.b(GeodatabaseFeatureServiceTable.this.getServiceUrl() + '/' + j2 + "/attachments/" + j3, hashMap, n.a(GeodatabaseFeatureServiceTable.this.getServiceUrl(), GeodatabaseFeatureServiceTable.this.credentials)));
                        ByteArrayInputStream retrieveAttachment2 = GeodatabaseFeatureServiceTable.this.retrieveAttachment(j2, j3);
                        CallbackListener callbackListener4 = callbackListener;
                        if (callbackListener4 != null) {
                            callbackListener4.onCallback(retrieveAttachment2);
                        }
                        return retrieveAttachment2;
                    }
                    return null;
                }
            });
        } catch (RejectedExecutionException unused) {
            return null;
        }
    }

    public void dispose() {
        if (this.Q) {
            return;
        }
        this.Q = true;
        if (this.b != null) {
            this.b.dispose();
        }
    }

    public String getServiceUrl() {
        return this.z + "/" + this.a;
    }

    @Override // com.esri.core.geodatabase.GeodatabaseFeatureTable
    public Future<Map<Long, FeatureResult>> queryRelated(final RelatedQueryParameters relatedQueryParameters, final CallbackListener<Map<Long, FeatureResult>> callbackListener) {
        if (this.I != Status.INITIALIZED) {
            throw new IllegalStateException(l);
        }
        a(relatedQueryParameters);
        return e.b.submit(new Callable<Map<Long, FeatureResult>>() { // from class: com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.2
            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public Map<Long, FeatureResult> call() throws Exception {
                try {
                    try {
                        if (Thread.currentThread().isInterrupted()) {
                            throw new InterruptedException();
                        }
                        Relationship relationship = GeodatabaseFeatureServiceTable.this.getRelationship(relatedQueryParameters.getRelationshipId());
                        GeodatabaseFeatureServiceTable geodatabaseFeatureServiceTable = relationship != null ? (GeodatabaseFeatureServiceTable) relationship.getRelatedTable() : null;
                        if (geodatabaseFeatureServiceTable == null) {
                            throw new IllegalStateException(GeodatabaseFeatureServiceTable.p);
                        }
                        if (geodatabaseFeatureServiceTable.getStatus() == Status.UNINITIALIZED) {
                            geodatabaseFeatureServiceTable.initialize();
                        }
                        if (geodatabaseFeatureServiceTable.getStatus() != Status.INITIALIZED) {
                            throw new IllegalStateException(GeodatabaseFeatureServiceTable.q);
                        }
                        relatedQueryParameters.setOutSpatialReference(GeodatabaseFeatureServiceTable.this.getSpatialReference());
                        FeatureRequestMode featureRequestMode = geodatabaseFeatureServiceTable.getFeatureRequestMode();
                        int i2 = AnonymousClass3.a[featureRequestMode.ordinal()];
                        if (i2 != 1 && i2 != 2 && i2 != 3) {
                            throw new UnsupportedOperationException(String.format(GeodatabaseFeatureServiceTable.o, GeodatabaseFeatureServiceTable.this.J));
                        }
                        boolean z = featureRequestMode == FeatureRequestMode.ON_INTERACTION_NO_CACHE;
                        Map<Long, FeatureResult> a2 = GeodatabaseFeatureServiceTable.this.a(relatedQueryParameters, geodatabaseFeatureServiceTable, z, z);
                        CallbackListener callbackListener2 = callbackListener;
                        if (callbackListener2 != null) {
                            callbackListener2.onCallback(a2);
                        }
                        return a2;
                    } catch (Exception e) {
                        CallbackListener callbackListener3 = callbackListener;
                        if (callbackListener3 != null) {
                            callbackListener3.onError(e);
                        }
                        throw e;
                    }
                } catch (Throwable th) {
                    CallbackListener callbackListener4 = callbackListener;
                    if (callbackListener4 != null) {
                        callbackListener4.onCallback(null);
                    }
                    throw th;
                }
            }
        });
    }

    protected void finalize() throws Throwable {
        super.finalize();
        dispose();
    }

    private File a(InputStream inputStream, String str, String str2) throws IOException {
        if (inputStream == null) {
            return null;
        }
        File createTempFile = File.createTempFile(str, str2);
        FileOutputStream fileOutputStream = new FileOutputStream(createTempFile);
        try {
            byte[] bArr = new byte[4096];
            while (true) {
                int read = inputStream.read(bArr);
                if (read == -1) {
                    return createTempFile;
                }
                fileOutputStream.write(bArr, 0, read);
            }
        } finally {
            fileOutputStream.close();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(InputStream inputStream, int i2, boolean z, boolean z2) throws IOException {
        if (inputStream == null) {
            return;
        }
        File file = null;
        try {
            file = a(inputStream, "EsriFeatures", ".json");
            synchronized (this.H) {
                a(file.getAbsolutePath(), i2, z, z2);
            }
        } finally {
            inputStream.close();
            if (file != null) {
                file.delete();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(long j2, InputStream inputStream) throws IOException {
        if (inputStream == null) {
            return;
        }
        File file = null;
        try {
            file = a(inputStream, "EsriAttachmentInfos", ".json");
            synchronized (this.H) {
                a(j2, file.getAbsolutePath());
            }
        } finally {
            inputStream.close();
            if (file != null) {
                file.delete();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(long j2, long j3, InputStream inputStream) throws IOException {
        if (inputStream == null) {
            return;
        }
        File file = null;
        try {
            file = a(inputStream, "EsriAttachment", ".byte");
            synchronized (this.H) {
                a(j2, j3, file.getAbsolutePath());
            }
        } finally {
            inputStream.close();
            if (file != null) {
                file.delete();
            }
        }
    }

    private void a(String str, int i2, boolean z, boolean z2) throws IOException {
        nativeImportFeaturesByFilePath(getHandle(), i2, str, true, z, z2);
    }

    private void a(long j2, String str) throws IOException {
        if (str != null) {
            nativeImportAttachmentInfosByFilePath(getHandle(), this.a, j2, str);
        }
    }

    private void a(long j2, long j3, String str) {
        if (str != null) {
            nativeImportAttachmentByFilePath(getHandle(), this.a, j2, j3, str);
        }
    }

    protected List<Map<String, Object>> getAddedAttachments() {
        return a(nativeGetInsertedAttachmentJSONMap(getHandle(), this.a));
    }

    protected List<Map<String, Object>> getDeletedAttachments() {
        return a(nativeGetDeletedAttachmentJSONMap(getHandle(), this.a));
    }

    protected List<Map<String, Object>> getUpdatedAttachments() {
        return a(nativeGetUpdatedAttachmentJSONMap(getHandle(), this.a));
    }

    private List<Map<String, Object>> a(String str) {
        ArrayList arrayList = new ArrayList();
        if (str != null) {
            try {
                JsonParser c = d.c(str);
                if (!d.c(c)) {
                    return null;
                }
                while (c.nextToken() != JsonToken.END_OBJECT) {
                    if ("attachmentattributes".equals(c.getCurrentName())) {
                        while (c.nextToken() != JsonToken.END_ARRAY) {
                            if ("attachment".equals(c.getCurrentName())) {
                                c.nextToken();
                                arrayList.add(d.a(c));
                            }
                        }
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return arrayList;
    }

    public long lookupObjectID(long j2) {
        long[] nativeCheckIDs = nativeCheckIDs(getHandle(), this.a, new long[]{j2});
        if (nativeCheckIDs == null || nativeCheckIDs.length == 0) {
            throw new IllegalArgumentException("Object ID does not match a feature in the table.");
        }
        return nativeCheckIDs[0];
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class a {
        private a() {
        }

        public static List<String> a(JsonParser jsonParser) throws JsonParseException, IOException {
            if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
                return null;
            }
            ArrayList arrayList = new ArrayList();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (GeodatabaseFeatureServiceTable.x.equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            arrayList.add(new ObjectMapper().readTree(jsonParser).toString());
                        }
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            return arrayList;
        }
    }
}
